package com.lcf.user.delay;

import java.util.concurrent.DelayQueue;

public class DelayQueueTest {

    public static void main(String[] args) {
        // 创建延时队列
        DelayQueue<Message> queue = new DelayQueue<>();
        int num = 0;
        long delayTime = 3000;
        // 添加延时消息,m1 延时5s
        Message m1 = new Message(1, "world", delayTime, num);
        // 添加延时消息,m2 延时3s
        //Message m2 = new Message(2, "hello", 10000);
        //queue.offer(m2);
        queue.offer(m1);
//        // 启动消费线程
//        new Thread(new Consumer(queue)).start();
//        System.out.println(Thread.currentThread().getName());
        System.out.println("当前线程：" + Thread.currentThread().getName());
        DelayConsumer delayConsumer = new DelayConsumer(queue);
        delayConsumer.run();
        System.out.println("发送成功，异步发送，不影响主线程");
    }

}
